#!/bin/bash
set -e;
natfrp_version='0.51.0-sakura-2'
project_name='natfrp-vpn'
echo "copy files......"
whoname=`whoami`
sudo mkdir -p /opt/${project_name}/logs;sudo chmod -R 755 /opt/${project_name};
sudo chown -R ${whoname} /opt/${project_name};
if [ -f /opt/${project_name}/frpc_linux_arm64 ];then
	sudo systemctl stop ${project_name}||echo 'skip'
	rm -f /opt/${project_name}/frpc_linux_arm64;
fi;
wget https://nya.globalslb.net/natfrp/client/frpc/${natfrp_version}/frpc_linux_arm64 -O /opt/${project_name}/frpc_linux_arm64
cp st*.sh /opt/${project_name}/;
cp *.service /opt/${project_name}/;
chmod -R 755 /opt/${project_name}/;

sed -i "s/User=.*/User=${whoname}/g" /opt/${project_name}/${project_name}.service;
sudo cp /opt/${project_name}/${project_name}.service /lib/systemd/system/${project_name}.service;
sudo systemctl daemon-reload;



if [ -e /opt/${project_name}/natfrp-tunnel ]; then
    echo "There is having /opt/${project_name}/natfrp-tunnel , ignore init natfrp-tunnel!"
	echo "start services......"
	sudo systemctl enable --now ${project_name};
else
    cp natfrp-tunnel /opt/${project_name}/;
	echo "please config /opt/${project_name}/natfrp-tunnel, then to start [/opt/${project_name}/start.sh]"

fi;


